<?php
require_once 'common.php';
/**
* 错误信息插入数据库
*/
class ErrorLog extends Common
{
	public function index()
	{
		$res = $this->check();
		switch ($res) {
			case 1:
				return Api::factory()->response(401, '参数不合法');
				break;
			case 2:
				return Api::factory()->response(402, 'app_id不存在');
				break;
			case 3:
				return Api::factory()->response(403, '没有该权限');
				break;
			default:
				break;
		}
		if (isset($_POST['error_log'])) {
			$errorLog = $_POST['error_log'];
		} else {
			return Api::factory()->response(401, '日志为空');
		}
		$sql = "INSERT INTO error_log(app_id,did,version_id,version_mini,error_log,create_time) VALUES({$this->params['app_id']},'{$this->params['did']}',{$this->params['version_id']},{$this->params['version_mini']},'{$errorLog}'," . time() . ")";
		$connect = DB::getInstance()->connect();
		if ($connect->query($sql)) {
			return Api::factory()->response(200, '错误信息插入成功');
		} else {
			return Api::factory()->response(400, '错误信息插入失败');
		}
	}
}
$error = new ErrorLog();
$error->index();